﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using YArchitech.LIB.YJKControls;

namespace YJKStairs.CommonUnit
{
	public class StairsFormManager
	{
		public static List<System.Windows.Forms.Control> GetControlAllTextBox(System.Windows.Forms.Control ctrl)
		{
			List<System.Windows.Forms.Control> list = new List<System.Windows.Forms.Control>();
			if (ctrl != null)
			{
				foreach (object obj in ctrl.Controls)
				{
					System.Windows.Forms.Control control = (System.Windows.Forms.Control)obj;
					if (control is System.Windows.Forms.TextBox && control.Visible && control.Enabled)
					{
						System.Windows.Forms.TextBox textBox = control as System.Windows.Forms.TextBox;
						if (textBox != null && !textBox.ReadOnly)
						{
							list.Add(control);
						}
					}
					else if (control is Panel)
					{
						List<System.Windows.Forms.Control> controlAllTextBox = StairsFormManager.GetControlAllTextBox(control);
						if (controlAllTextBox.Count > 0)
						{
							list.AddRange(controlAllTextBox);
						}
					}
					else if (control is YJKGroupBoxBlackSide)
					{
						List<System.Windows.Forms.Control> controlAllTextBox2 = StairsFormManager.GetControlAllTextBox(control);
						if (controlAllTextBox2.Count > 0)
						{
							list.AddRange(controlAllTextBox2);
						}
					}
				}
			}
			return list;
		}

		public static bool IsInvalidFormInput(System.Windows.Forms.Form form)
		{
			bool result = false;
			if (form != null)
			{
				List<System.Windows.Forms.Control> controlAllTextBox = StairsFormManager.GetControlAllTextBox(form);
				System.Windows.Forms.Control control = null;
				if (ValueValidatingKit.IsInvalidControlTextValue(controlAllTextBox, ref control))
				{
					if (control != null)
					{
						MessageBox.Show("界面参数输入有误，请修正！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Hand);
						control.Focus();
					}
					result = true;
				}
			}
			return result;
		}
	}
}
